import * as cc from 'cc';
const { ccclass } = cc._decorator;
@ccclass('HelloWorld')
export class HelloWorld extends cc.Component {
    start() {
        //演示直接设置Node属性
        let bearNode = this.node.getChildByPath('Node属性演示/Bear');
        cc.tween(bearNode)
            .by(2, { x: 500, y: -300, scaleX: 2, scaleY: 0.5 })
            .by(2, { widthUT: -50, heightUT: -50, angleZ: 150 })
            .by(2, { x: -500, y: 300, scaleX: -2, scaleY: -0.5 })
            .by(2, { widthUT: 50, heightUT: 50, angleZ: -150 })
            .union()
            .repeatForever()
            .start();
        //演示设置节点颜色渐变（渐变效果会影响子节点）
        let colorNode = this.node.getChildByPath('颜色渐变演示/Kun');
        colorNode.setColor(3, cc.color(255, 0, 0));
        //演示设置节点振动
        let shakeNode = this.node.getChildByPath('节点振动演示/Kun');
        //无限振动，水平振幅50
        shakeNode.shake(-1, cc.v3(50, 0));
        let ratNode = this.node.getChildByPath('节点振动演示/Rat');
        //无限振动，垂直振幅50
        ratNode.shake(-1, cc.v3(0, 50));
        let dogNode = this.node.getChildByPath('节点振动演示/Dog');
        //振动10次，水平振幅100，垂直振幅100，振动频率1秒
        dogNode.shake(10, cc.v3(100, 100), 0.1);
        //findChildren返回所有名称为'Title'的节点
        let titleNodes = this.node.findChildren('Title');
        this.schedule(() => {
            //换一次标题颜色
            for (let i = titleNodes.length - 1; i > -1; --i) {
                titleNodes[i].setColor(2, cc.color(Math.random() * 255, Math.random() * 255, Math.random() * 255));
            }
            colorNode.setColor(2, colorNode['defaultColor'] ? undefined : cc.color(255, 0, 0));
            dogNode.shake(20, cc.v3(100, 100), 0.05);
        }, 3)
    }
}


